package com.example.administrator.zhongyichou.help;

import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;

import com.example.administrator.zhongyichou.R;
import com.tbruyelle.rxpermissions2.RxPermissions;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * Created by lichenyu on 2017/11/29.
 * 描述：
 */

public class CallPhone {
    public static void call(final Activity activity, final String phone) {
        //获取权限
        new RxPermissions(activity).request(Manifest.permission.CALL_PHONE)
                .subscribe(new Observer<Boolean>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(Boolean value) {
                        if (value) {//如果所有权限都通过
                            Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + phone));
                            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            activity.startActivity(intent);
                        }
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
